<template>
  <div class="card-title">
    <div class="title-content">
      <!-- 左侧图标和标题区域 -->
      <div class="title-left">
        <div class="title-icon">
          <slot name="icon">
            <!-- 恢复原来的图标 -->
            <div class="default-icon"></div>
          </slot>
        </div>
        <div class="title-text">
          <h3>{{ title }}</h3>
          <div class="title-sub" v-if="subtitle">{{ subtitle }}</div>
        </div>
      </div>

      <!-- 右侧装饰和详情区域 -->
      <div class="title-right">
        <div class="title-decoration">
          <!-- decoration-line 改为插槽 -->
          <slot name="decoration">
            <!-- 默认的装饰线 -->
            <div class="decoration-line"></div>
          </slot>
        </div>
        <div class="detail-area" v-if="showDetail">
          <slot name="detail">
            <!-- 默认详情内容 -->
            <div class="default-detail" @click="handleDetailClick">
              <span class="detail-text">详情</span>
              <div class="detail-icon">
                <svg
                  viewBox="0 0 24 24"
                  fill="none"
                  xmlns="http://www.w3.org/2000/svg"
                >
                  <path
                    d="M9 18L15 12L9 6"
                    stroke="currentColor"
                    stroke-width="2"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  />
                </svg>
              </div>
            </div>
          </slot>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CardTitle",
  props: {
    title: {
      type: String,
      default: "标题",
    },
    subtitle: {
      type: String,
      default: "",
    },
    showDetail: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    handleDetailClick() {
      this.$emit("detail-click");
    },
  },
};
</script>

<style lang="scss" scoped>
.card-title {
  width: calc(100% - 60px);
  padding-inline: 30px;
  margin-block: 10px;

  .title-content {
    display: flex;
    align-items: center;
    height: 60px;
    position: relative;

    .title-left {
      display: flex;
      align-items: center;
      flex: 1;
    }

    .title-icon {
      width: 40px;
      height: 40px;
      margin-right: 12px;
      display: flex;
      align-items: center;
      justify-content: center;

      .default-icon {
        width: 24px;
        height: 24px;
        background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
        border-radius: 4px;
        position: relative;

        &::before {
          content: "";
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          width: 12px;
          height: 12px;
          background: #ffffff;
          clip-path: polygon(0 0, 100% 50%, 0 100%);
        }
      }
    }

    .title-text {
      flex: 1;

      h3 {
        color: #ffffff;
        font-size: 22px;
        font-weight: 600;
        margin: 0;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        background: linear-gradient(135deg, #ffffff 0%, #bae7ff 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        letter-spacing: 1px;
      }

      .title-sub {
        color: #87d068;
        font-size: 12px;
        margin-top: 2px;
        opacity: 0.8;
      }
    }

    .title-right {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      flex: 1;

      .title-decoration {
        flex: 1;
        max-width: 200px;
        margin-right: 20px;
        display: flex;
        align-items: center;
        justify-content: center;

        .decoration-line {
          height: 2px;
          width: 100%;
          background: linear-gradient(
            90deg,
            transparent 0%,
            rgba(24, 144, 255, 0.8) 30%,
            rgba(24, 144, 255, 0.4) 70%,
            transparent 100%
          );
          border-radius: 1px;
        }
      }

      .detail-area {
        .default-detail {
          display: flex;
          align-items: center;
          padding: 6px 12px;
          background: linear-gradient(
            135deg,
            rgba(24, 144, 255, 0.1) 0%,
            rgba(9, 109, 217, 0.1) 100%
          );
          border: 1px solid rgba(24, 144, 255, 0.3);
          border-radius: 4px;
          cursor: pointer;
          transition: all 0.3s ease;

          &:hover {
            background: linear-gradient(
              135deg,
              rgba(24, 144, 255, 0.2) 0%,
              rgba(9, 109, 217, 0.2) 100%
            );
            border-color: rgba(24, 144, 255, 0.6);
          }

          .detail-text {
            color: #bae7ff;
            font-size: 12px;
            font-weight: 500;
            margin-right: 6px;
          }

          .detail-icon {
            width: 12px;
            height: 12px;
            color: #1890ff;

            svg {
              width: 100%;
              height: 100%;
            }
          }
        }
      }
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .card-title {
    padding: 0 15px;

    .title-content {
      height: 50px;

      .title-icon {
        width: 32px;
        height: 32px;
        margin-right: 10px;

        .default-icon {
          width: 20px;
          height: 20px;

          &::before {
            width: 10px;
            height: 10px;
          }
        }
      }

      .title-text h3 {
        font-size: 18px;
      }

      .title-right {
        .title-decoration {
          max-width: 100px;
          margin-right: 10px;
        }

        .detail-area .default-detail {
          padding: 4px 8px;

          .detail-text {
            font-size: 11px;
          }

          .detail-icon {
            width: 10px;
            height: 10px;
          }
        }
      }
    }
  }
}
</style>